import Vue from 'vue'
import Vuex from 'vuex'
import Const from '../const'

Vue.use(Vuex)

const user = {
  state: {
    userName: '未登录'
  },
  mutations: {
    setUserName(state, data) {
      state.userName = data
    }
  }
}

const global = {
  state: {
    count: 0,
    widgets: {
      loadingMask: {
        show: false,
        tips: '数据加载中，请稍后...',
        type: Const.LOADING_TYPE.CIRCLE
      }
    }
  },
  getters: {
    loadingMask: state => {
      return state.widgets.loadingMask
    }
  },
  mutations: {
    showLoadingMask: state => {
      state.widgets.loadingMask.show = true
    },
    hideLoadingMask: (state) => {
      state.widgets.loadingMask.show = false
    }
  }
}

export default new Vuex.Store({
  modules: {
    global: global,
    user: user
  }
})
